﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class AddImmuneCommandHander : IRequestHandler<AddImmuneCommand, ApiResult<object>>
    {
        public readonly IRepistory<Immune> _immuneRepository;
        public readonly IMapper _mapper;

        public AddImmuneCommandHander(IRepistory<Immune> immuneRepository, IMapper mapper)
        {
            _immuneRepository = immuneRepository;
            _mapper = mapper;
        }
        /// <summary>
        /// 健康信息添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<object>> Handle(AddImmuneCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> apiResult=new ApiResult<object>();
            var result=  _mapper.Map<Immune>(request);
            _immuneRepository.Add(result);
            apiResult.code = Renum.添加成功;
            apiResult.Message = Renum.添加成功.ToString();
            apiResult.Data = result;
            return Task.FromResult(apiResult);  
        }
    }
}
